import React, {PureComponent} from 'react';
import styles from './index.less';
import {Table, Alert, Badge, Switch, Icon, InputNumber, Tooltip, Popconfirm,Button}  from 'antd';
import {powerControl} from '../../utils/powerControl';
const AuthButton = powerControl(Button);

class ShippingList extends PureComponent {

    state = {
        selectedRowKeys: [],
        totalCallNo: 0,
    };

    componentWillReceiveProps(nextProps) {
        if (nextProps.selectedRows.length === 0) {
            this.setState({
                selectedRowKeys: [],
                totalCallNo: 0,
            });
        }
    }
    handleEditRow = (record, pagination) => {
        this.props.onEditRow(record, pagination);
    }

    handleTableChange = (pagination, filters, sorter) => {
        this.props.onChange(pagination, filters, sorter);
    }

    handleDelRow = (shipping_id, pagination) => {
        this.props.onDelRow(shipping_id, pagination);
    }

    render(){
          const {selectedRowKeys, totalCallNo} = this.state;
          const {data: {list, pagination}, loading} = this.props;
          const columns = [
            {
                title: '配送方式编码', dataIndex: 'shipping_code',fixed: 'left',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.shipping_code}>
                        <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '配送方式名称', dataIndex: 'shipping_name',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.shipping_name}>
                        <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '配送方式描述', dataIndex: 'shipping_desc',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.shipping_desc}>
                        <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '保价费用', dataIndex: 'insure',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.insure}>
                       <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '是否支持货到付款', dataIndex: 'support_cod',
                render(val) {
                    return <Switch checkedChildren={<Icon type="check"/>} unCheckedChildren={<Icon type="cross"/>}
                                   defaultChecked={val} checked={val}/>;
                },
            },

            {
                title: '是否被禁用', dataIndex: 'enabled',
                render(val) {
                    return <Switch checkedChildren={<Icon type="check"/>} unCheckedChildren={<Icon type="cross"/>}
                                   defaultChecked={val} checked={val}/>;
                },
            },

            {
                title: '操作',
                // fixed: 'right',
                render: (val, record) => (
                    <p>
                        <AuthButton auth="shipping.edit" ghost  className={styles.btn} size="small" onClick={() => this.handleEditRow(record, pagination)}>编辑</AuthButton>
                        <span className={styles.splitLine}/>
                        <Popconfirm title="是否确定删除?" onConfirm={() => this.handleDelRow(record.shipping_id, pagination)} >
                            <AuthButton auth="shipping.delete" ghost  className={styles.btn} size="small">删除</AuthButton>
                        </Popconfirm>
                    </p>
                ),
            },
        ];

        const paginationProps = {
            showSizeChanger: true,
            showQuickJumper: true,
            ...pagination,
        };
        return (
            <div className={styles.standardTable}>
                <Table
                loading={loading}
                rowKey={record => record.shipping_id}
                // rowSelection={rowSelection}
                dataSource={list}
                columns={columns}
                pagination={paginationProps}
                onChange={this.handleTableChange}
                scroll={{x: 1000}}
            />
            </div>
        )

    }
}
export default ShippingList;

